const app = getApp();

function commentSorts(list) {
    let newOpinion = list;
    var newuserId = app.globalData.userId;
    if(newOpinion.length > 0 && newOpinion !== []){
        var p = [];
        newOpinion.forEach( item => {
          if(item.userId == newuserId){
            p.push(item);
          }
        });
        p.forEach( items => {
          for(let i = 0; i<p.length;i++){
                if(p[i] == items){
                  items.sorts = i + 1;
                }
              }
        })
        for(var a = 0; a < p.length-1; a++){
          for(var b = 0; b< p.length-1-a; b++){
              if(p[b].sorts < p[b+1].sorts){
              var temp = p[b];
              p[b] = p[b+1];
              p[b+1] = temp;
              }
          }
        };
        return p;
    }else{
        return
    }
}
module.exports = {
    handleSort: commentSorts
}